package com.adv.ems.utils;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class EmsDateUtil {

    public static List<Date> getCalendarDays(Date date) {
        DateTime beginOfMonth = DateUtil.beginOfMonth(date);
        DateTime endOfMonth = DateUtil.beginOfDay(DateUtil.endOfMonth(date));
        int b = DateUtil.dayOfWeek(beginOfMonth) - 1;
        while (b > 1) {
            beginOfMonth.offset(DateField.HOUR, -24);
            b --;
        }
        int e = DateUtil.dayOfWeek(endOfMonth) - 1;
        while (e < 7) {
            endOfMonth.offset(DateField.HOUR, 24);
            e ++;
        }
        List<Date> dates = new ArrayList<Date>();
        while (beginOfMonth.before(endOfMonth) || beginOfMonth.equals(endOfMonth)) {
            Date time = beginOfMonth.toCalendar().getTime();
            dates.add(time);
            beginOfMonth.offset(DateField.HOUR, 24);
        }
        return dates;
    }
}
